package com.linoer.cloud.alo.accountservice.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linoer.cloud.alo.accountservice.domain.Account;
import com.linoer.cloud.alo.accountservice.mapper.AccountMapper;
import com.linoer.cloud.alo.common.domain.ObjectResponse;
import com.linoer.cloud.alo.common.domain.dto.AccountDTO;
import com.linoer.cloud.alo.common.domain.enums.ResponseStatus;
import org.springframework.stereotype.Service;

/**
 * @Classname AccountServiceImp
 * @Description 账户服务
 * @Date 2021/6/22 9:28 下午
 * @Created by muhenglv
 */
@Service
public class AccountServiceImp extends ServiceImpl<AccountMapper, Account> implements AccountService {

    /**
     * 减少账户金额
     * @param account   账户信息
     * @return          操作结果
     */
    @Override
    public ObjectResponse decreaseAccount(AccountDTO account) {
        ObjectResponse response = new ObjectResponse<>();
        int result = this.baseMapper.decreaseAccount(account.getUserId(), account.getMoney());
        if (result < 0){
            response.setStatus(ResponseStatus.FAIL.getCode());
            response.setMessage(ResponseStatus.FAIL.getMessage());
        }else {
            response.setStatus(ResponseStatus.SUCCESS.getCode());
            response.setMessage(ResponseStatus.SUCCESS.getMessage());
        }
        return response;
    }
}
